How to insert SUPER AND GEOMETRY data type values? #79
-
https://github.com/aws/amazon-redshift-python-driver#supported-datatypes From the mapping i see above super and geometry is mapped to string,
Can you kindly add an example? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Thank you for this feedback. We will add examples to our docs, likely in the form of a tutorial. In the meantime I've added some docs below -- feel free to let me know what other examples/information would be helpful :) GeometryWhen sending Geometry datatype, use WKB (well known binary) format unless passing to a Redshift server method such as Geometry datatype is received in WKB format. SuperWhen sending super datatype, send it as a string. If your Python datatype is a When receiving super datatype, a string is received. Examplescursor.execute("create table datatype_test (c1 geometry, c2 super);")
cursor.execute(
"insert into datatype_test (c1, c2) values (ST_GeomFromText(%s), json_parse(%s));",
(
'LINESTRING(1 2,3 4,5 6,7 8,9 10,11 12,13 14,15 16,17 18,19 20)', # here we use WKT format
json.dumps({1: "hello", 2: "world"})
)
)
cursor.execute("select c1, c2 from datatype_test;")
result = cursor.fetchone()
print("c1={}\nc2={}".format(result[0], result[1]))
cursor.execute("create table datatype_test (c1 geometry, c2 super);")
cursor.execute(
"insert into datatype_test (c1) values (%s);",
(
'0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000',
# using wkb format
)
)
cursor.execute("select c1 from datatype_test;")
result = cursor.fetchone()
print("c1={}\n".format(result[0],))
|
Beta Was this translation helpful? Give feedback.
-
Hi @kishaningithub , we've added a new tutorial in our latest release 2.0.904. Amazon Redshift Datatypes, which can be found linked from our project README, covers uses of Amazon Redshift specific datatypes. Please let me know if there are other functionalities you'd like to see demonstrated in our tutorials. |
Beta Was this translation helpful? Give feedback.
Thank you for this feedback. We will add examples to our docs, likely in the form of a tutorial. In the meantime I've added some docs below -- feel free to let me know what other examples/information would be helpful :)
Geometry
When sending Geometry datatype, use WKB (well known binary) format unless passing to a Redshift server method such as
ST_GeomFromText()
. In that case, a WKT (well known text) representation should be used. Available Redshift server methods can be found, with examples, here.Geometry datatype is received in WKB format.
Super
When sending super datatype, send it as a string. If your Python datatype is a
dict
, usejson.dumps
.When receiving super datatype, a string i…