ST_MakeTexture

更新时间:
复制 MD 格式

Constructs a texture object in PolarDB for PostgreSQL (GanosBase). Load texture images from a URL or file path, from raw binary data, or by referencing an existing texture stored in another table.

Syntax

Three overloads are available. Choose based on where your image data lives:

Variant 1 — Load from a URL or file path

texture ST_MakeTexture(integer width,
                       integer height,
                       cstring url,
                       boolean to_internal  DEFAULT false,
                       integer depth        DEFAULT 3,
                       cstring format       DEFAULT 'JPEG',
                       cstring compression  DEFAULT 'None',
                       cstring wrap         DEFAULT 'Wrap');

Variant 2 — Reference an existing texture in a table

texture ST_MakeTexture(cstring table_name,
                       cstring column_name,
                       cstring key_value,
                       cstring schema_name  DEFAULT 'public');

Variant 3 — Load from a binary data stream

texture ST_MakeTexture(integer width,
                       integer height,
                       bytea data,
                       integer depth        DEFAULT 3,
                       cstring format       DEFAULT 'JPEG',
                       cstring compression  DEFAULT 'None',
                       cstring wrap         DEFAULT 'Wrap');

Parameters

Variant 1 and Variant 3 parameters

ParameterTypeDefaultDescription
widthintegerThe width of the texture image, in pixels.
heightintegerThe height of the texture image, in pixels.
urlcstringThe URL or file path of the texture image. Applies to Variant 1 only.
databyteaThe binary data stream of the texture image. Applies to Variant 3 only.
to_internalbooleanfalseSpecifies whether to store the image binary data inline in the database. Set to true to embed the data in the texture column; false keeps a reference to the external file. Applies to Variant 1 only.
depthinteger3The bit depth of the texture image. Valid values: 1 (grayscale), 3 (RGB), 4 (RGBA).
formatcstring'JPEG'The format of the texture image. Valid values: 'Raw', 'JPEG', 'PNG'.
compressioncstring'None'The compression method for the binary data stream. Valid values: 'None' (no compression), 'Zlib' (zlib compression).
wrapcstring'Wrap'The wrap mode of the texture image. Valid values: 'Wrap', 'Mirror'.

Variant 2 parameters

ParameterTypeDefaultDescription
table_namecstringThe name of the table that contains the existing texture.
column_namecstringThe name of the column that contains the existing texture.
key_valuecstringThe ID of the existing texture. This parameter is used in the WHERE clause. For example, 'id=1'.
schema_namecstring'public'The name of the schema that contains the table.

Storage modes

Binary data can be stored in three ways. Choose based on your data size and access requirements:

ModeHow it worksUse when
Inline in the databaseThe binary stream is stored directly in the texture column (use Variant 1 with to_internal = true, or Variant 3).Textures are small and frequently accessed; no external file management is needed.
External file referenceThe texture column stores a reference to an external file path; the binary stream stays on disk (use Variant 1 with to_internal = false).Textures are large and database storage size matters; accept that file access may be slower.
Cross-table referenceThe texture column stores a pointer to a texture row in another table (use Variant 2).Multiple models share the same texture and you want to avoid duplicating the binary data.

Examples

All examples use the same base table:

CREATE TABLE textures(id integer, the_texture texture);

Store a PNG image inline

Load a 225×225 RGBA PNG from a file path and embed the binary data directly in the database. After insertion, the texture column holds the full binary content — no external file access is needed at query time.

INSERT INTO textures VALUES (
    1,
    ST_MakeTexture(225, 225, 'path/example.png'::cstring, true, 4, 'PNG')
);

Keep the binary data in an external file

Load a 225×225 RGB JPEG and keep the binary stream in the external file. The texture column stores only a reference to the file path. The binary stream is read from disk each time the texture is accessed.

INSERT INTO textures VALUES (
    2,
    ST_MakeTexture(225, 225, 'path/example.jpeg'::cstring, false, 3, 'JPEG')
);

Provide a binary stream directly

Insert a 256×256 RGB JPEG by passing the binary data as a bytea value. The format defaults to 'JPEG' and depth defaults to 3 (RGB).

INSERT INTO textures VALUES (
    3,
    ST_MakeTexture(256, 256, '\x123abcd...'::bytea)
);
-- Replace '\x123abcd...' with the actual hex-encoded binary content.

Reference an existing texture

Create a cross-table reference to the texture where id = 1 in the same table. The key_value argument is evaluated as a WHERE clause condition. No binary data is duplicated; the new row points to the existing texture.

INSERT INTO textures VALUES (
    4,
    ST_MakeTexture('textures'::cstring, 'the_texture'::cstring, 'id=1')
);